﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>装修公司</title>
    <link href="~/Content/Css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="~/Content/Css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="~/Content/Css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="~/Content/Css/animate.css" rel="stylesheet">
    <link href="~/Content/Css/style.css?v=4.1.0" rel="stylesheet">
    <style>
        .ibox {
            margin-bottom: 0px;
        }

        .ibox-content {
            padding: 15px 20px 0px 20px;
        }
    </style>
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>装修公司</h5>
            </div>
            <div class="ibox-content">
                <div class="row row-lg">
                    <div class="col-sm-10">
                        <div class="btn-group">
                            <button id="insertBtn" type="button" class="btn btn-outline btn-default">
                                <i class="glyphicon glyphicon-plus" aria-hidden="true"></i>
                            </button>
                            <button id="editBtn" type="button" class="btn btn-outline btn-default">
                                <i class="glyphicon glyphicon-edit" aria-hidden="true"></i>
                            </button>
                            <button id="deleteBtn" type="button" class="btn btn-outline btn-default">
                                <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
                            </button>
                            <button id="refreshBtn" type="button" class="btn btn-outline btn-default">
                                <i class="glyphicon glyphicon-refresh" aria-hidden="true"></i>
                            </button>
                        </div>
                    </div>
                    <div class="col-sm-2">
                        <div class="input-group">
                            <input id="searchKey" type="text" class="form-control" placeholder="请输入要搜索的内容...">
                            <span class="input-group-btn">
                                <button id="searchBtn" type="button" class="btn btn-primary">
                                    搜索
                                </button>
                            </span>
                        </div>
                    </div>
                </div>

                <div class="row row-lg">
                    <div class="col-sm-12">
                        <table id="table"></table>
                    </div>
                </div>
            </div>
        </div>
        @* 用来传递消息的隐藏域 *@
        <input id="handle_status" value="" hidden="hidden">
    </div>


    <!-- 全局js -->
    <script type="text/javascript" src="~/Scripts/jquery.min.js?v=2.1.4"></script>
    <script type="text/javascript" src="~/Scripts/bootstrap.min.js?v=3.3.6"></script>
    <!-- 自定义js -->
    <script type="text/javascript" src="~/Scripts/content.js?v=1.0.0"></script>
    <!-- Bootstrap table -->
    <script type="text/javascript" src="~/Scripts/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script type="text/javascript" src="~/Scripts/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>

    <!-- layer javascript -->
    <script type="text/javascript" src="~/Scripts/plugins/layer/layer.min.js"></script>

    <script type="text/javascript">
        $(function () {
            initTable();

            if (!isAuthority('253')) {
                $('#insertBtn').show();
                $('#editBtn').show();
                $('#deleteBtn').show();
            }

        });
        var $table = $('#table');
        function initTable() {
            $table.bootstrapTable({
                url: '/DecorationCompany/GetList',
                method: 'post',                     //数据请求方式
                striped: true,                      //是否显示行间隔色
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: true,                   //是否启用分页
                sidePagination: 'server',           //在服务器端分页
                queryParams: queryParams,           //传递参数
                pageNumber: 1,                      //初始化加载第一页，默认第一页
                pageSize: 20,                       //每页的记录行数（*）
                pageList: [10, 20, 30, 40, 50],     //可供选择的每页的行数（*）
                clickToSelect: true,                //是否启用点击选中行
                //toolbar: "#tableToolBar",
                height: getHeight(),
                columns: [{
                    width: 38,
                    field: 'selected',
                    checkbox: true,
                }, {
                    field: 'id',
                    title: '行号',
                    align: 'center',
                    //cellStyle: function cellStyle(value, row, index) {

                    //    if (row.showIndex > 0) {
                    //        return {
                    //            css: {
                    //                "font-weight": "bold", "color": "red"
                    //            }
                    //        };
                    //    }
                    //    return {};

                    //},
                }, {
                    field: 'name',
                    title: '名称',
                    align: 'center'
                }, {
                    field: 'brokerage',
                    title: '佣金',
                    align: 'center',
                    formatter: CutOut
                }, {
                    field: 'bandSawBrokerage',
                    title: '佣金规则',
                    align: 'center',
                    formatter: CutOut
                }, {
                    field: 'awardDescription',
                    title: '奖励说明',
                    align: 'center',
                    formatter: CutOut
                }, {
                    field: 'commissionAccount',
                    title: '佣金帐期',
                    align: 'center'
                }, {
                    field: 'filingRules',
                    title: '报备规则',
                    align: 'center',
                    formatter: CutOut
                }, {
                    field: 'bandSawRules',
                    title: '带看规则',
                    align: 'center',
                    formatter: CutOut
                }, {
                    field: 'transactionRules',
                    title: '成交规则',
                    align: 'center',
                    formatter: CutOut
                }, {
                    field: 'decorationCompanyInfo',
                    title: '公司简介',
                    align: 'center'
                }, {
                    field: 'starTarget',
                    title: '星标',
                    align: 'center',
                    formatter: FormatterstarTarget
                }
                //, {
                //    field: 'starTargetRemark',
                //    title: '星标备注',
                //    align: 'center'
                //}
                , {
                    field: 'remark',
                    title: '备注',
                    align: 'center',
                    formatter: CutOut
                }, {
                    field: 'mediumOfCommunicationStaffName',
                    title: '渠道人员',
                    align: 'center'
                }, {
                    field: 'feeScale',
                    title: '收费标准',
                    align: 'center',
                    formatter: CutOut
                }, {
                    field: 'preferential',
                    title: '优惠信息',
                    align: 'center',
                    formatter: CutOut
                }
                //, {
                //    title: '置顶操作',
                //    align: 'center',
                //    formatter: TopFormatter
                //}
                , {
                    field: 'id',
                    title: '佣金分组',
                    align: 'center',
                    formatter: FormatterBrokerageList
                }, {
                    field: 'id',
                    title: '图片管理',
                    align: 'center',
                    formatter: PictureManagementFormatter
                }, {
                    field: 'id',
                    title: '门店管理',
                    align: 'center',
                    formatter: FormatterStoreManagement
                }, {
                    field: 'id',
                    title: '设计方案',
                    align: 'center',
                    formatter: FormatterCaseManagement
                }
                ],
                onLoadSuccess: function (data) {
                    if (data.total == 0) {
                        $(".ibox-content").css("padding-bottom", "22px");
                    } else {
                        $(".ibox-content").css("padding-bottom", "4px");
                    }
                }
            });
        }

        //查询的参数
        var queryParams = function (params) {
            var temp = {
                pageSize: params.limit,                             //行数
                pageIndex: (params.offset / params.limit) + 1,      //页码
                search: $('#searchKey').val()                       //查询内容
            };
            //console.info(temp);
            return temp;
        };
        function FormatterBrokerageList(value, row, index) {
            return [
                    '<a class="kv-file-zoom btn btn-xs btn-primary" href="javascript:void(0)"  onclick="BrokerageList(' + value + ')">',
                    '佣金分组',
                    '</a>  ',
            ].join('');
        }
        function BrokerageList(id) {
            parent.layer.open({
                type: 2,
                title: '佣金分组',
                shadeClose: false,
                shade: 0.4,
                area: ['960px', '750px'],
                content: '/Account/Brokerage/BrokerageGroupList?ModuleID=' + 4 + '&ItemID=' + id,
                end: function () {
                    refreshTable();
                }
            });

        }
        ////置顶操作
        //function TopFormatter(value, row, index) {
        //    return [
        //        '<a class="kv-file-zoom btn btn-xs btn-primary" href="javascript:void(0)"  onclick="TopEditData(' + row.id + ',' + row.buildingTopId + ')">',
        //        '置顶操作',
        //        '</a>  ',
        //    ].join('');
        //}
        //图片管理
        function PictureManagementFormatter(value, row, index) {
            if (parseInt(row['imageCount']) == 0) {
                return [
                '<a class="recordpic" href="javascript:void(0)" onclick="PictureManagementeditData(' + value + ')"  title="装修公司图片">',
                '<i class="glyphicon glyphicon-upload"></i>',
                '</a>  '
                ].join('');
            } else {
                return [
                '<a class="recordpic" href="javascript:void(0)" onclick="PictureManagementeditData(' + value + ')" title="装修公司图片">',
                '<i class="glyphicon glyphicon-picture"></i>',
                '×' + row['imageCount'],
                '</a>  '
                ].join('');
            }

            //return [
            //    '<a class="kv-file-zoom btn btn-xs btn-primary" href="javascript:void(0)"  onclick="PictureManagementeditData(' + value + ')">',
            //    '图片管理',
            //    '</a>  ',
            //].join('');
        }
        function PictureManagementeditData(id) {
            parent.layer.open({
                type: 2,
                title: '添加图片',
                shadeClose: false,
                shade: 0.4,
                area: ['960px', '750px'],
                content: '/Images/Index?GroupID=' + 6 + '&InterfixID=' + id + '&ImageType=' + 0,
                end: function () {
                    refreshTable();
                }
            });
        }
        function FormatterStoreManagement(value, row, index) {
            return [
                '<a class="kv-file-zoom btn btn-xs btn-primary" href="javascript:void(0)"  onclick="StoreManagement(' + value + ')">',
               '门店管理',
               '</a>  ',
            ].join('');
        }
        //门店管理页面
        function StoreManagement(id) {
            parent.layer.open({
                type: 2,
                title: '门店管理',
                shadeClose: false,
                shade: 0.4,
                area: ['960px', '750px'],
                content: '/Decoration/DecorationCompanyStore/Index?id=' + id,
                end: function () {
                    refreshTable();
                }
            });
        }
        function FormatterCaseManagement(value, row, index) {
            return [
                '<a class="kv-file-zoom btn btn-xs btn-primary" href="javascript:void(0)"  onclick="CaseManagement(' + value + ')">',
               '设计方案',
               '</a>  ',
            ].join('');
        }
        //设计方案管理页面
        function CaseManagement(id) {
            parent.layer.open({
                type: 2,
                title: '设计方案',
                shadeClose: false,
                shade: 0.4,
                area: ['1200px', '850px'],
                content: '/Decoration/DecorationCompanyCase/CaseIndex?id=' + id,
                end: function () {
                    refreshTable();
                }
            });
        }
        //星标
        function FormatterstarTarget(value, row, index) {

            if (value == 0) {
                var str = "无";
                return [
              '<a class="kv-file-zoom btn btn-xs btn-default" href="javascript:void(0)"  onclick="starTargetSet(' + value + ',' + row.id + ')">',
              '<i">' + str + '</i>',
              '</a>  '
                ].join('');
            }
            if (value == 1) {
                var str = "客户信用不良";
                return [
              '<a class="kv-file-zoom btn btn-xs btn-primary" href="javascript:void(0)"  onclick="starTargetSet(' + value + ',' + row.id + ')">',
              '<i">' + str + '</i>',
              '</a>  '
                ].join('');
            }
            if (value == 2) {
                var str = "客户首付分期";
                return [
              '<a class="kv-file-zoom btn btn-xs btn-default" style="background-color: #55a2ed;" href="javascript:void(0)"  onclick="starTargetSet(' + value + ',' + row.id + ')">',
              '<i">' + str + '</i>',
              '</a>  '
                ].join('');
            }
            if (value == 3) {
                var str = "客户全款购买";
                return [
              '<a class="kv-file-zoom btn btn-xs btn-danger" href="javascript:void(0)"  onclick="starTargetSet(' + value + ',' + row.id + ')">',
              '<i">' + str + '</i>',
              '</a>  '
                ].join('');
            }
            if (value == 4) {
                var str = "别墅洋房";
                return [
              '<a class="kv-file-zoom btn btn-xs btn-success" style="background-color: #dc5fce;" href="javascript:void(0)"  onclick="starTargetSet(' + value + ',' + row.id + ')">',
              '<i">' + str + '</i>',
              '</a>  '
                ].join('');
            }
            if (value == 5) {
                var str = "其他";
                return [
              '<a class="kv-file-zoom btn btn-xs btn-warning" href="javascript:void(0)"  onclick="starTargetSet(' + value + ',' + row.id + ')">',
              '<i">' + str + '</i>',
              '</a>  '
                ].join('');
            }
        }
        //星标标设置
        function starTargetSet(value, id) {
            parent.layer.open({
                type: 2,
                title: "星标类型",
                shadeClose: false,
                shade: 0.4,
                area: ["800px", "260px"],
                content: "/Decoration/DecorationCompany/SetStarTarget?id=" + id,
                end: function () {
                    refreshTable();
                }
            });
        }
        //刷新表格数据
        var refreshTable = function () {
            $table.bootstrapTable('refresh');
        }

        //自定义的列事件
        function operateFormatter(value, row, index) {
            return [
                '<a class="edit" href="javascript:void(0)" title="编辑">',
                '<i class="glyphicon glyphicon-edit"></i>',
                '</a>  ',
                '<a class="remove" href="javascript:void(0)" title="删除">',
                '<i class="glyphicon glyphicon-remove"></i>',
                '</a>'
            ].join('');
        }

        window.operateEvents = {
            'click .edit': function (e, value, row, index) {

            },
            'click .remove': function (e, value, row, index) {

            }
        };


        function isTrueFormatter(value, row, index) {
            return value ? '<i class="glyphicon glyphicon-ok"></i>' : '<i class="glyphicon glyphicon-remove"></i>'
        }

        //获取表格高度
        function getHeight() {
            return $(window).height() - 150;
        }

        //重置表格高度
        setTimeout(function () {
            $table.bootstrapTable('resetView');
        }, 200);

        //重置表格高度
        $(window).resize(function () {
            $table.bootstrapTable('resetView', {
                height: getHeight()
            });
        });

        //刷新按钮
        $('#refreshBtn').click(function (e) {
            $table.bootstrapTable('refresh');
        });

        //搜索按钮
        $('#searchBtn').click(function (e) {
            $table.bootstrapTable('refresh');
        });

        //插入按钮
        $('#insertBtn').click(function (e) {
            parent.layer.open({
                type: 2,
                title: '添加装修公司',
                shadeClose: false,
                shade: 0.4,
                area: ['960px', '640px'],
                content: '/Decoration/DecorationCompany/Insert',
                end: function () {
                    refreshTable();
                }
            });
        });

        //编辑按钮
        $('#editBtn').click(function (e) {
            var selected = $table.bootstrapTable('getSelections');

            if (selected.length > 1) {
                layer.msg("一次只能修改一条数据！", { icon: 5, time: 2000 });
                return;
            }

            if (selected.length == 0) {
                layer.msg("请选择您要修改的数据！", { icon: 5, time: 2000 });
                return;
            }
            editData(selected[0].id);
        });

        //打开编辑窗口
        function editData(id) {
            parent.layer.open({
                type: 2,
                title: '修改装修公司信息',
                shadeClose: false,
                shade: 0.4,
                area: ['960px', '640px'],
                content: '/Decoration/DecorationCompany/Edit?id=' + id,
                end: function () {
                    refreshTable();
                }
            });
        }

        //删除按钮
        $('#deleteBtn').click(function (e) {
            var selected = $table.bootstrapTable('getSelections');
            if (selected.length == 0) {
                layer.msg("请选择您要删除的数据！", { icon: 5, time: 2000 });
                return;
            }

            var arr = [];
            for (var i = 0; i < selected.length; i++) {
                arr.push(selected[i].id);
            }

            var ids = arr.join(",");

            layer.confirm('您确定要删除所选数据吗', {
                btn: ['是的', '取消'] //按钮
            }, function () {
                $.ajax({
                    url: "/Decoration/DecorationCompany/DeleteAsync",
                    type: "post",
                    dataType: "json",
                    data: { ids: ids },
                    success: function (data) {
                        //Info,Success,Warning,Error
                        var type = data.type;
                        if (type == 1) {
                            layer.msg(data.content,
                                {
                                    icon: 6, time: 2000
                                },
                                function () {
                                    refreshTable();
                                });
                        } else {
                            layer.msg(data.content, { icon: 5, time: 2000 });
                        }
                    }
                });
            }, function () {
                return;
            });
        });
        function CutOut(value, row, index) {
            if (value !== null && value !== undefined && value !== '') {
                if (value.length > 7) {
                    value = value.substring(0, 5) + '..';
                }
            }            
            return [
               value
            ].join('');
        }
    </script>
</body>
</html>
